<template>
  <div class="page-main">
          <group class="page-main-head">
      <cell>
        <div slot="title"
             class="page-main-head-title">
              {{inviteBidData[0].InviteBidTopic}}
        </div>
        <div slot="inline-desc"
             class="page-main-head-section">
          <span>发布日期:
            <strong style="color: #000000;font-size:14px">{{inviteBidData[0].EmitBidTime|formatDate}}</strong>
          </span>
        </div>
      </cell>
    </group>

     <tab :line-width="2"
           active-color="#DC220B">
        <tab-item selected
                  @on-item-click="currentTab=1">疑问列表</tab-item>
        <tab-item @on-item-click="currentTab=2">答疑文件</tab-item>
      </tab>

    <group v-show="currentTab===1" class="page-main-content"  v-for="(item,index) in pageData " :key="index">
      <cell>
        <div slot="title">
          <div>
            <span class="div-name-span">问</span>
            <span class="question-title">{{item.QuestionTitle}}</span>
          </div>
  
          <div class="question-content">
            {{item.QuestionContent}}
          </div>
          <div class="question-footer">
            <div class="question-footer-left">
              {{item.QuestionType}}
            </div>
            <div class="question-footer-rigth">
              {{item.QuestionTime|formatDate}}
            </div>
          </div>
        </div>
      </cell>
      <!-- <cell v-show="item.Status==='已回复'">
        <div slot="title">
          <div>
            <span class="div-name-span"
                  style="background:#27C86B">答</span>
            <span class="question-title">答复参见详细文档</span>
            <span style="float:right;color:#888888;font-size:14px">{{pageData.AnswerTime|formatDate}}</span>
          </div>
  
         
        </div>
      </cell>
       <cell v-show="item.Status!=='已回复'">
        <div slot="title">
          <div>
            <span class="div-name-span"
                  style="background:#27C86B">答</span>
            <span class="question-title-no-answar" >暂无相关回复</span>
          </div>
        </div>
      </cell> -->
    </group>   


  <group class="page-main-content" v-show="currentTab===2"  >
      <cell v-for="(item,index) in documents " :key="index" @click.native="displayFile(item)">
          <div slot="title">
         <div class="question-content">
           <img :src="require('../../assets/img/'+item.icon)" class="content-document-icon">
           </img>
            <div class="content-document-name"  >
             {{item.DocName}}
            </div>
          </div>
        </div>
      </cell>
 </group>     

  <div v-transfer-dom>
            <x-dialog v-model="isPic"
                      class="dialog-demo"
                      hide-on-blur>
              <div class="img-box">
                <img :src="picUrl"
                     style="max-width:100%">
              </div>
              <div @click="isPic=false">
                <span class="vux-close"></span>
              </div>
            </x-dialog>
          </div>
    <div style="margin-top:5px">
      <x-button type="warn"
                @click.native="$router.push({path:'/demos/invite-bid-question-form',
        query:{InviteBidGUID:$route.query.InviteBidGUID,
              CgPlanGUID:$route.query.CgPlanGUID,
              InviteBidForenoticeGUID:$route.query.InviteBidForenoticeGUID
         }
        })" class="bottom-button-red" :disabled="isExpire" >
        我要提问
      </x-button>
    </div>
  
  </div>
</template>

<script>
import { Search, Tab, TabItem, Group, Cell, XButton, Icon, XDialog, TransferDomDirective as TransferDom } from 'vux'
import { InviteBidQuestionService, MyInviteBidService } from '../../service/Services.js'
import _ from 'lodash'
import Utils from '../../utils/utils'

export default {
  name: 'CellBtn',
  directives: {
    TransferDom
  },
  components: {
    Search,
    Tab,
    TabItem,
    Group,
    Cell,
    XButton,
    Icon,
    XDialog
  },
  data () {
    return {
      searchText: '',
      pageData: [],
      inviteBidData: [{InviteBidTopic: '', EmitBidTime: ''}], // 招标预告数据,
      currentTab: 1,
      documents: [],
      isPic: false,
      picUrl: '',
      isExpire: false
    }
  },
  methods: {
    loadData () {
      this.$vux.loading.show({
        text: '加载中...'
      })
      var providerGUID = this.$store.getters.getUserInfo.ProviderGUID
      let inviteBidGUID = this.$route.query.InviteBidGUID
     //  let inviteBidForenoticeGUID = this.$route.query.InviteBidForenoticeGUID
      MyInviteBidService.getInviteBid(inviteBidGUID).then((res) => {
        this.inviteBidData = res.Data
        // 当前时间和截止时间对比
        let currentDate = new Date()
        let msec = res.Data[0].EndBidTime.match(/\d+[+]\d+/gi)
        let endBidTime = new Date(Number.parseInt(msec))
        if (currentDate > endBidTime) {
          this.isExpire = true
        }
      })
      InviteBidQuestionService.getInviteBidQuestion(providerGUID, inviteBidGUID).then((res) => {
        this.$vux.loading.hide()
        this.pageData = res.Data
        this.documents = res.Documents
        Utils.fmtDocument(this.documents)
      })
    },
    changeTab (index) {
      this.currentTab = index
    },
    displayFile (item) {
      if (item.icon === 'word.png' || item.icon === 'excel.png' || item.icon === 'pdf.png') {
        this.$router.push({ path: '/demos/display-file', query: { docUrl: item.Url } })
      } else if (item.DocName.indexOf('.png') > -1 || item.DocName.indexOf('.jpg') > -1) {
        // 展示图片
        this.isPic = true
        this.picUrl = item.Url
      }
    }
  },
  computed: {
    getResult () {
      return _.filter(this.pageData, item => {
        return item.ForenoticeTitle.indexOf(this.searchText) !== -1 ||
          item.Status.indexOf(this.searchText) !== -1
      })
    }
  },
  created () {
    this.loadData()
  }
}
</script>
<style scoped lang="less">
.page-main {
  font-family: PingFangSC-Regular;
  letter-spacing: 0;
  margin-bottom: 30px;
  .page-main-head {
    .page-main-head-title {
      font-size: 18px;
      color: #000000;
      font-weight: bold;
    }
  }
}

.question-title {
  font-family: PingFangSC-Medium;
  font-size: 15px;
  color: #000000;
  letter-spacing: 0;
  font-weight: bold;
}

.question-content {
  font-family: PingFangSC-Regular;
  font-size: 14px;
  color: #333333;
  letter-spacing: 0;
  line-height: 25px;
  margin-left: 23px;
  margin-top: 10px;
}

.question-footer {
  margin-left: 23px;
  color: #888888;
  margin-top: 5px;
}

.question-footer-left {
  float: left;
  text-align: center;
  border: 1px solid #888888;
  border-radius: 12px;
  font-family: PingFangSC-Regular;
  padding: 3px 3px;
  font-size: 13px;
  letter-spacing: 2px;
}

.question-footer-rigth {
  float: right;
  font-size: 14px;
}

.div-name-span {
  background: #f13907;
  position: relative;
  color: #FFFFFF;
  padding: 2px 2px;
  font-size: 13px;
}

.content-document-icon {
  width: 38px;
  height: 40px;
  float: left;
}

.content-document-name {
  float: left;
  position: relative;
  top: 5px;
  left: 10px;
  color: #888888;
  font-size: 12px;
}
.question-title-no-answar{
  font-family: PingFangSC-Regular;
  font-size: 14px;
  color: #333333;
  letter-spacing: 0;
  line-height: 25px;
}
.page-main-content-background{
  min-height: 250px;
  padding-top:50px;
  font-size: 13px;
  color: #9B9B9B;
}
.no-answer-img{
  background-image: url(../../assets/img/no-answer.png);
  background-repeat: no-repeat;
  background-size: 100% 100%;
  margin: 0 auto;
  height: 110px;
  width: 130px;
}
 .bottom-button-red {
    box-shadow: 0px -2px 2px 0px rgba(0, 0, 0, 0.05);
    border-top: 1px solid #e5e3e6;
    position: fixed;
    bottom: 0;
    left: 0;
    color: white;
    background-color: red;
  }
   .bottom-button-red:disabled{
      background-color: #EEEEEE;
      color:#c9c8ca;
   }
</style>
